package com.elai.analytics.controller;
import com.alibaba.fastjson.JSONObject;
import com.elai.analytics.domain.ColumnHeader;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.utils.ThirdProperties;
import org.apache.commons.collections4.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 只能推荐Controller
 *
 * @author elai
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/report/ascribe")
public class AscribeAnalyticsController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(AscribeAnalyticsController.class);

    @Autowired
    private ThirdProperties thirdProperties;




    @PostMapping("/ascribeAnalyQuery")
    public AjaxResult ascribeAnalyQuery(@RequestBody String requestJson)
    {
        /*
         [{
            id: 3,
            value1: '$APP激活的启动时长',
            value2: '368',
            value3: '368',
            value4: '128',
            value5: '3218',
            value6: '60'
          }]
        */
        log.info("keepAnalyQuery："+requestJson);
        JSONObject paramJson = JSONObject.parseObject(requestJson);
        JSONObject keepJson = paramJson.getJSONObject("requestJson");

        Map<String, Object> paramMap =new HashedMap();
        Map<String,Object> resultMap=new HashMap();

        //列表表头
        List<ColumnHeader> tableTitle=new ArrayList<ColumnHeader>();
        tableTitle.add(new ColumnHeader("eventName","指标","",true));
        tableTitle.add(new ColumnHeader("total","总人数","",true));
        tableTitle.add(new ColumnHeader("firist","第一日","",true));

        //列表数据
        List<Map<String,String>> tableData=new ArrayList<>();

        Map<String,String> data2=new HashMap();
        data2.put("id","2");
        data2.put("eventName","$APP激活的启动时长");
        data2.put("total","368");
        data2.put("firist","28.59");
        tableData.add(data2);

        Map<String,String> data3=new HashMap();
        data3.put("id","3");
        data3.put("eventName","$APP激活的启动时长");
        data3.put("total","368");
        data3.put("firist","28.59");
        tableData.add(data3);

        Map<String,String> data4=new HashMap();
        data4.put("id","4");
        data4.put("eventName","$APP激活的启动时长");
        data4.put("total","645");
        data4.put("firist","2354359");
        tableData.add(data4);

        resultMap.put("tableTitle",tableTitle);
        resultMap.put("tableData",tableData);

        return AjaxResult.success(resultMap);
    }

}
